home *** CD-ROM | disk | FTP | other *** search
- procedure TForm1.Print1Click(Sender: TObject);
- var
- InfoSize: Integer; { used to determine size of memory to allocate for}
- { a TBitmapInfo structure }
- ImageSize: Integer; { Used to determine size of memory to allocatefor }
- { bitmap bits }
- Info: PBitmapInfo; { Pointer to a TBitmapInfo structure which }
- { contains information on the dimensions and color }
- { of a Windows device independent bitmap }
- Image: Pointer; { Pointer to the DIB bits which is an array of bytes }
- ImWidth, ImHeight: Integer; { Used for calculating size of image on the }
- { destination canvas }
- begin
- with Image1.Picture.Bitmap do begin
- { Call GetDIBSizes which returns the amount of memory needed to
- allocate for both the DIB info header and the DIB bitmap bits }
- GetDIBSizes(Handle, InfoSize, ImageSize);
- { Allocate memory for the info header based on the size obtained from
- GetDIBSizes }
- Info := MemAlloc(InfoSize);
- try
- { Allocate memory for the Image based on the size from GetDIBSizes }
- Image := MemAlloc(ImageSize);
- try
- { Retrieve the color palette information, the info header and the
- bitmap bits with the GetDIB procedure }
- GetDIB(Handle, Palette, Info^, Image^);
- with Info^.bmiHeader do begin
- Printer.BeginDoc; // Start a print job
- try
- { Calculate the size of the output rectangle to which the
- image will be drawn. This will be based on one-half of the
- printer's page width }
- ImWidth := Printer.PageWidth div 2;
- ImHeight := trunc((ImWidth / biWidth) * biHeight);
- { Draw the information from the source bitmap to the
- destination device context, which is the printer's canvas }
- StretchDIBits(Printer.Canvas.Handle, 0, 0, ImWidth,
- ImHeight, 0, 0, biWidth, biHeight, Image, Info^,
- DIB_RGB_COLORS, SRCCOPY);
- finally
- Printer.EndDoc; // End the print job
- end;
- end;
- finally
- FreeMem(Image, ImageSize); // Free the allocated memory
- end;
- finally
- FreeMem(Info, InfoSize); // Free the allocated memory
- end;
- end;
- end;